﻿#pragma once
#include<variant>
#include <type_traits>
#include <utility>  
#include "BusinessDataTypes.h"

namespace model {
	class LogicalBody {
	public:
		uint8_t subCommand = 0x00;

		// 使用std::monostate作为第一个类型，允许默认构造时不初始化实际业务类型
		model::BusinessDataTypes business_fields_;
		
        // 用于设置业务数据的模板方法
        template <typename T>
        void setBusinessDataFields(const T& data) {
            static_assert(std::is_constructible_v<model::BusinessDataTypes, T>, "不支持的业务数据类型");
            business_fields_ = data;
        }
        template <typename T>
        void setBusinessDataFields(T&& data) {
            static_assert(std::is_constructible_v<model::BusinessDataTypes, T>, "不支持的业务数据类型");
            business_fields_ = data;
        }
        // 用于获取业务数据的模板方法
        template <typename T>
        T& getBusinessDataFields() {
            return std::get<T>(business_fields_);
        }
        /*template <typename T>
        const T& getBusinessDataFields() const {
            return std::get<T>(business_fields_);
        }*/
        // 检查是否为特定业务数据类型
        template <typename T>
        bool isBusinessDataType() const {
            return std::holds_alternative<T>(business_fields_);
        }
	};
}